<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="min40 column">
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					姓名
				</view>
				<u--input placeholder="请输入姓名" inputAlign="right" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="name"></u--input>
			</view>
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					身份证号
				</view>
				<u--input placeholder="请输入身份证号" maxlength="18" inputAlign="right" placeholderStyle="font-size: 28rpx;"
					border="none" v-model="id_card"></u--input>
			</view>
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					手机号
				</view>
				<u--input placeholder="请输入手机号" maxlength="11" inputAlign="right" placeholderStyle="font-size: 28rpx;"
					border="none" v-model="phone"></u--input>
			</view>
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					所属银行
				</view>
				<u--input placeholder="请输入所属银行" inputAlign="right" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="affiliation"></u--input>
			</view>
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					开户行
				</view>
				<u--input placeholder="请输入开户行" inputAlign="right" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="bank"></u--input>
			</view>
			<view class="row padbottom20 mintop20 align_item_c border_bottom">
				<view class="font600 size30" style="color: #2E3C2A;width: 80px;">
					银行卡号
				</view>
				<u--input placeholder="请输入银行卡号" inputAlign="right" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="bank_number"></u--input>
			</view>
		</view>
		<view class="min30 padtop40">
			<u-button text="绑定银行卡" shape="circle" color="#FFAD4C" @click="getApply">
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user_id: '',
				name: '',
				id_card: '',
				phone: '',
				affiliation: '',
				bank: '',
				bank_number: '',
				type: ''
			}
		},

		onLoad() {
			this.user_id = uni.getStorageSync('user_id');
			this.type = uni.getStorageSync('user_type');
		},
		methods: {
			async getApply() {
				var _this = this
				var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
				var id =
					/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/;
				if (!_this.name) return this.$com.toast('请输入姓名');
				if (!_this.id_card) return this.$com.toast('请输入身份证号');
				if (!id.test(_this.id_card)) return this.$com.toast('身份证号输入不正确');
				if (!_this.phone) return this.$com.toast('请输入手机号');
				if (!strTemp.test(_this.phone)) return this.$com.toast('手机号输入不正确');
				if (!_this.affiliation) return this.$com.toast('请输入所属银行');
				if (!_this.bank) return this.$com.toast('请输入开户行');
				if (!_this.bank_number) return this.$com.toast('请输入银行卡号');

				let {
					code,
					message,
					data
				} = await this.$com.fetch('member/BankCards', {
					user_id: _this.user_id,
					name: _this.name,
					phone: _this.phone,
					id_card: _this.id_card,
					affiliation: _this.affiliation,
					bank: _this.bank,
					bank_number: _this.bank_number,
				});

				if (code == 200) {
					uni.showToast({
						icon: 'success',
						title: message
					})
					if (this.type == 2) {
						setTimeout(function() {
							uni.reLaunch({
								url: '/pages/store/my'
							});
						}, 1000)
					} else {
						setTimeout(function() {
							uni.switchTab({
								url: '/pages/user/my'
							});
						}, 1000)
					}

				} else {
					uni.showToast({
						icon: 'none',
						title: message
					})
				}

			},
		}
	}
</script>

<style scoped lang="less">
	.border_bottom {
		border-bottom: 2rpx solid #DADADA;
	}
</style>